import web
import re

def getconfig(file, section):
  f = open(file, "r")
  dic_cfg = {}
  found = False
  for line in f.readlines():
    if line != "[{0}]\n".format(section) and found == False:
      continue
    if re.match("\s*\[(\w+)\]\s*", line) != None and found == True:
      break
    m = re.match("\s*(\w+)\s*=\s*\"(.*)\"\s*", line)
    if m != None:
      dic_cfg[m.group(1)] = m.group(2)
    found = True
  return dic_cfg
  
db_cfg = getconfig("config.ini", "database")
db = web.database(dbn = "mysql", db = db_cfg["db"], user = db_cfg["db_user"], pw = db_cfg["db_psw"])
  